package com.wanxi.servlet;

import com.wanxi.model.CompanyModel;
import com.wanxi.model.NavModel;
import com.wanxi.model.ProductModel;
import com.wanxi.service.CompanyService;
import com.wanxi.service.NavService;
import com.wanxi.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1.乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("utf-8");
//        2.得到前端的值
//        3.封装model
//        4.调用服务逻辑层
        CompanyService companyService = new CompanyService();
        NavService navService = new NavService();
        ProductService productService=new ProductService();
//        5.将数据返回给前端页面
        CompanyModel companyModel = companyService.getCompanyModel();
        List<NavModel> navModelList = navService.getNavModelList();
        List<ProductModel> productModelList=productService.getHomeProductData();
        req.setAttribute("companyModel", companyModel);
        req.setAttribute("navModelList", navModelList);
        req.setAttribute("news", "");
        req.setAttribute("productModelList", productModelList);
        req.getRequestDispatcher("/jsp/home.jsp").forward(req, resp);

    }
}
